package algorithm.strategy;

import algorithm.PersonAgeDiff;

import java.util.List;
import java.util.Optional;

/**
 * 求最小年龄差
 */
public class AgeDiffMinStrategy implements IAgeDiffStrategy {

    @Override
    public PersonAgeDiff get(List<PersonAgeDiff> ageDiffList) {
        Optional<PersonAgeDiff> ageDiff = ageDiffList.stream().min(COMPARING_BY_AGE_DIFF);
        if (!ageDiff.isPresent()) {
            throw new RuntimeException("获取最小年龄差失败");
        }

        return ageDiff.get();
    }
}
